package org.mspring.mlog.service;

import org.mspring.mlog.dao.ResourceEntityDao;
import org.mspring.mlog.entity.ResourceEntity;
import org.mspring.nbee.common.PageResult;
import org.mspring.nbee.db.dao.sql.builder.part.condition.SqlCondition;
import org.mspring.nbee.db.dao.sql.pager.SqlPager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author Gao Youbo
 * @since 2014-09-10 12:44:48
 */
@Service
public class ResourceEntityService {

    private static final Logger LOG = LoggerFactory.getLogger(ResourceEntityService.class);

    private ResourceEntityDao resourceEntityDao;

    public ResourceEntity findById(long id) {
        return resourceEntityDao.findById(id);
    }

    public PageResult<ResourceEntity> list(List<SqlCondition> conditions, SqlPager pager) {
        return resourceEntityDao.listPage(conditions, pager);
    }

    /**
     * 根据角色查询角色对应资源
     *
     * @param roleId
     * @return
     */
    public List<ResourceEntity> listByRole(long roleId) {
        return resourceEntityDao.listByRole(roleId);
    }

    public List<ResourceEntity> listAll() {
        return resourceEntityDao.listAll();
    }

    @Transactional
    public boolean update(ResourceEntity resource) {
        return resourceEntityDao.update(resource);
    }

    @Transactional
    public boolean deleteById(long id) {
        return resourceEntityDao.deleteById(id);
    }

    @Autowired
    public void setResourceEntityDao(ResourceEntityDao resourceEntityDao) {
        this.resourceEntityDao = resourceEntityDao;
    }

}
